package com.moon.controller;

import com.moon.anno.Lmt;
import com.moon.repository.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.moon.utils.BaseController;
import com.moon.entity.Student;
import com.moon.service.StudentService;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/moon/Student")
public class StudentController extends BaseController {
    @Autowired
    private StudentService studentService;

    //按部门与性别查询
    @Cacheable(cacheNames = "cache0", key = "#root.targetClass.simpleName+':'+#root.methodName+':'+#root.args")
    @RequestMapping("/selectByDeptAndSex")
    @ResponseBody
    public List<Student> selectByDeptAndSex(String dept, String sex) {
        List list = studentService.selectByDeptAndSex(dept, sex);
        return list;
    }

    //按id删除
    @CacheEvict(cacheNames = "cache0", allEntries = true)
    @RequestMapping("/deleteById")
    @ResponseBody
    public String deleteById(int id) {
        studentService.deleteById(id);
        return "success";
    }

    @Autowired
    private StudentRepository studentRepository;

    @Lmt(1)
    @RequestMapping("/selectByJpa")
    @ResponseBody
    public List<com.moon.japentity.Student> selectByJpa() {
        List<com.moon.japentity.Student> list = studentRepository.findBySomeCond("中文系");
        return list;
    }
}